package prototype;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: homeWork
 * @description:
 * @author: hezhiqin
 * @create: 2019-09-26 10:08
 */
public class Test {
    public static void main(String[] args) {
        // 创建一个具体的需要克隆的对象
        ConcretePrototypeA concretePrototype = new ConcretePrototypeA();
        // 填充属性，方便测试
        concretePrototype.setAge(18);
        concretePrototype.setName("何智勤");
        List hobbies = new ArrayList<String>();
        concretePrototype.setHobbies(hobbies);
        System.out.println(concretePrototype);

        // 创建Client 对象，准备开始克隆
        Client client = new Client(concretePrototype);
        ConcretePrototypeA concretePrototypeClone = (ConcretePrototypeA)
                client.startClone(concretePrototype);
        System.out.println(concretePrototypeClone);
        System.out.println("克隆对象中的引用类型地址值：" + concretePrototypeClone.getHobbies());
        System.out.println("原对象中的引用类型地址值：" + concretePrototype.getHobbies());
        System.out.println("对象地址比较："+(concretePrototypeClone.getHobbies() ==
                concretePrototype.getHobbies()));
        //浅克隆。只是完整
        //复制了值类型数据，没有赋值引用对象
        concretePrototypeClone.setAge(19);
        System.out.println(concretePrototype.getAge());
    }
}
